import axios from 'axios'

const instance = axios.create({
    baseURL: 'https://www.ahsj.link/nebula-api',
    timeout:5000
})
//请求拦截
instance.interceptors.request.use(config => { 


     if(config.method==="put"){
                console.log(config)
                config.headers = {
                    /* put请求的头设置 */
                    "Content-Type": 'application/x-www-form-urlencode',
                }
            }

    let token = localStorage.getItem('token');
    if(token){
        // 如果有token，就带到请求头中
        config.headers["x-auth-token"] = token;
    }
    return config
}, err => { 
    return Promise.reject(err)  
})

//响应拦截
instance.interceptors.response.use(result => { 
    return result.data
}, err => { 
    return Promise.reject(err)  
})

//导出单例
export default instance